#ifndef __KMALLOC_H_f57dbdf4eeb6488ba57a26c18f8494d3__
#define __KMALLOC_H_f57dbdf4eeb6488ba57a26c18f8494d3__

#include "stdint.h"
#include "mmngr_phys.h"
#include "mmngr_virtual.h"
#include "mmngr_virtual_pde.h"
#include "mmngr_virtual_pte.h"

#define HEAP_VIRT_START_BASE 0x20000000 //512mb
#define HEAP_SIZE 0xa00000 //10mb
#define HEAP_VIRT_END_BASE (HEAP_VIRT_START_BASE + HEAP_SIZE)

#define MAX_MAP_NUM 200

typedef struct _heap_map_entry
{
	void *entry;
	bool isUsed;
	uint32_t length;
}heap_map_entry;

typedef struct _heap_map
{
	heap_map_entry entrys[MAX_MAP_NUM];
	uint32_t size;
}heap_map;

typedef struct _kernel_heap
{
	heap_map heapMap;
	uint32_t startAddress;
	uint32_t endAddress;
	uint32_t maxAddress;
	uint32_t length;
}kernel_heap;

bool heap_map_entry_compare(void *item1,void *item2);

bool heap_map_insert(heap_map_entry *item,heap_map *heapMap);

void heap_map_delete(uint32_t index,heap_map *heapMap);

uint32_t heap_map_lookup_free_entry(heap_map *heap,uint32_t length,uint32_t align = 1);

void *heap_map_split(heap_map *heap,uint32_t index,uint32_t length,uint32_t align = 1);

void kmalloc_initialize();

void *kmalloc(uint32_t size,uint32_t align = 1);

void kfree(void *p);

#endif